/**
 * 状态管理
 * MVVM Library
 * className: StateX
 * version: 0.0.1
 * nextUpdate: NaN
 * updateTime: 2021/06/02
 * @Author 洛水天依 <luotianyiovo@gmail.com>
 */
class StateX {
    get = {}
    set = {}
    state = {}
    constructor(options = {
        get: {},
        set: {},
        state: {}
    }) {
        if (typeof StateX.instance === 'object') return StateX.instance
        StateX.instance = this

        this.get = options.get || {}
        this.set = options.set || {}
        this.state = options.state || {}
    }
    emit (key, data) {
        this.state[key] = data
        return this.state[key]
    }
    setAction (action, key, data) {
        return this.set[action].apply(this, [key, data, this.state[key]])
    }
    getAction (action, key) {
        return this.get[action].apply(this, [key, getObjectValue(this.state, key)])
    }
}
